package com.example.vehicleservice.bean1;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class VehicleData {

    /*

  "vin": "9HMDFEHHRQ9V50FP6",
  "timestamp": 1749215627263,
  "longitude": 118.019111,
  "latitude": 5.96983,
  "speed": 36.7,
  "mileage": 65213.52,
  "batteryLevel": 85.43,
  "batteryTemp": 54.85,
  "motorTemp": 61.06,
  "chargingStatus": "charging",
  "energyConsumption": 18.7
     */
    private String vin;                 // 车辆唯一标识
    private Long timestamp;             // 数据时间戳(毫秒)
    private Double longitude;          // 经度
    private Double latitude;           // 纬度
    private Double speed;              // 车速(km/h)
    private Double mileage;            // 总里程(km)
    private Double batteryLevel;      // 电池电量(%)
    private Double batteryTemp;       // 电池温度(℃)
    private Double motorTemp;         // 电机温度(℃)
    private String chargingStatus;   // 充电状态: charging/discharge
    private Double energyConsumption; // 瞬时能耗(kWh/100km)

    // 构造函数、getters和setters
    public VehicleData() {}

    // 可以从JSON解析的构造函数
    public VehicleData(String json) {
        // 这里简化为手动解析，实际应用中可用Gson/Jackson等库
        int vinStart = json.indexOf("\"vin\":") + 7;
        int vinEnd = json.indexOf("\",", vinStart);
        this.vin = json.substring(vinStart, vinEnd);

        int timestampStart = json.indexOf("\"timestamp\":") + 12;
        int timestampEnd = json.indexOf(",", timestampStart);
        this.timestamp = Long.parseLong(json.substring(timestampStart, timestampEnd));

        int longitudeStart = json.indexOf("\"longitude\":") + 12;
        int longitudeEnd = json.indexOf(",", longitudeStart);
        this.longitude = Double.parseDouble(json.substring(longitudeStart, longitudeEnd));

        int latitudeStart = json.indexOf("\"latitude\":") + 11;
        int latitudeEnd = json.indexOf(",", latitudeStart);
        this.latitude = Double.parseDouble(json.substring(latitudeStart, latitudeEnd));

        int speedStart = json.indexOf("\"speed\":") + 8;
        int speedEnd = json.indexOf(",", speedStart);
        this.speed = Double.parseDouble(json.substring(speedStart, speedEnd));

        int mileageStart = json.indexOf("\"mileage\":") + 9;
        int mileageEnd = json.indexOf(",", mileageStart);
        this.mileage = Double.parseDouble(json.substring(mileageStart, mileageEnd));

        int batteryLevelStart = json.indexOf("\"batteryLevel\":") + 15;
        int batteryLevelEnd = json.indexOf(",", batteryLevelStart);
        this.batteryLevel = Double.parseDouble(json.substring(batteryLevelStart, batteryLevelEnd));

        int batteryTempStart = json.indexOf("\"batteryTemp\":") + 14;
        int batteryTempEnd = json.indexOf(",", batteryTempStart);
        this.batteryTemp = Double.parseDouble(json.substring(batteryTempStart, batteryTempEnd));

        int motorTempStart = json.indexOf("\"motorTemp\":") + 12;
        int motorTempEnd = json.indexOf(",", motorTempStart);
        this.motorTemp = Double.parseDouble(json.substring(motorTempStart, motorTempEnd));

        int chargingStatusStart = json.indexOf("\"chargingStatus\":") + 17;
        int chargingStatusEnd = json.indexOf("\",", chargingStatusStart);
        this.chargingStatus = json.substring(chargingStatusStart, chargingStatusEnd);

        int energyConsumptionStart = json.indexOf("\"energyConsumption\":") + 20;
        int energyConsumptionEnd = json.indexOf("\",", energyConsumptionStart);
        this.energyConsumption = Double.parseDouble(json.substring(energyConsumptionStart, energyConsumptionEnd));
    }
}
